import permissionAuth from './permissionAuth'

const homeMenus = [
  {
    name: '首页',
    router: '/home/index',
    icon: 'HomeFilled'
  },
  {
    name: '基础数据管理',
    router: '/baseData',
    icon: 'DataLine',
    permission: 'baseData',
    children: [
      {
        name: '院系管理',
        router: '/baseData/collegeInfo',
        permission: 'baseData:collegeInfo'
      },
      {
        name: '专业管理',
        router: '/baseData/majorInfo',
        permission: 'baseData:majorInfo'
      },
      {
        name: '班级管理',
        router: '/baseData/classInfo',
        permission: 'baseData:classInfo'
      }
    ]
  },
  {
    name: '就业信息管理',
    router: '/employment',
    icon: 'DocumentCopy',
    permission: 'employment',
    children: [
      {
        name: '就业信息列表',
        router: '/employment/jobInfo',
        permission: 'employment:jobInfo'
      }
    ]
  },
  {
    name: '实习信息管理',
    router: '/internship',
    icon: 'Management',
    permission: 'internship',
    children: [
      {
        name: '实习信息列表',
        router: '/internship/internshipInfo',
        permission: 'internship:internshipInfo'
      }
    ]
  },
  {
    name: '企业管理',
    router: '/enterprise',
    icon: 'Search',
    permission: 'enterprise',
    children: [
      {
        name: '企业公告管理',
        router: '/enterprise/announcement',
        permission: 'enterprise:announcement'
      },
      {
        name: '企业用户列表',
        router: '/enterprise/enterpriseList',
        permission: 'enterprise:enterpriseList'
      }
    ]
  },
  {
    name: '辅导员用户管理',
    router: '/counsellor',
    icon: 'Management',
    permission: 'counsellor',
    children: [
      {
        name: '辅导员用户列表',
        router: '/counsellor/counsellorList',
        permission: 'counsellor:counsellorList'
      }
    ]
  },
  {
    name: '学生用户管理',
    router: '/student',
    icon: 'Stamp',
    permission: 'student',
    children: [
      {
        name: '学生用户列表',
        router: '/student/studentList',
        permission: 'student:studentList'
      }
    ]
  },
  {
    name: '个人中心',
    router: '/personal',
    icon: 'Tools',
    children: [
      {
        name: '个人信息',
        router: '/personal/userinfo'
      },
      {
        name: '修改密码',
        router: '/personal/password'
      }
    ]
  }
]
let homeMenu = []
function hasPermission() {
  homeMenus.forEach((item) => {
    //有permission的路由才做判断，没有的直接放进数组
    if (item.permission && !item.children) {
      if (permissionAuth(item.permission)) {
        homeMenu.push(item)
      }
    } else if (item.permission && item.children) {
      let obj = {}
      if (permissionAuth(item.permission)) {
        obj = {
          ...item,
          children: []
        }
        item.children.forEach((child) => {
          if (permissionAuth(child.permission)) {
            obj.children.push(child)
          }
        })
      }
      // 判断obj是否为空
      if (obj.router) {
        homeMenu.push(obj)
      }
    } else {
      homeMenu.push(item)
    }
  })
}
hasPermission()

export default homeMenu
